// miniprogram/pages/reservation/reservation.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  dingyue: function () {
    var _ = this;
    wx.requestSubscribeMessage({
      tmplIds: ['57GDx-i0lKA9iT2r7jSuY5XHyL5B1v14WGNaqNb_q-8'],
      success(res) {

        console.log(_.data.list)
        var openid = wx.getStorageSync('openid')
        var name = wx.getStorageSync('name')
        var mobile = wx.getStorageSync('mobile')
        wx.request({
          url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/trainingbase/upd_ver_info',
          method: 'POST',
          data: {
            name: name,
            mobile: mobile,
            other: openid
          },
          success(res) {
            console.log(res)
          }
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var _ = this;
    var name = wx.getStorageSync('name')
    var mobile = wx.getStorageSync('mobile')
    _.setData({
      name,
      mobile
    })
    wx.request({
      url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1//trainingbase/login',
      method: 'POST',
      data: {
        name: name,
        mobile: mobile
      },
      success(res) {
        console.log(res.data.list[0])
        var sex = res.data.list[0].sex
        var room_pn = res.data.list[0].room_pn
        var room_type = res.data.list[0].room_type
        var peer_status = res.data.list[0].peer_status
        var room_id = res.data.list[0].room_id
        room_id ? _.setData({
          room_id
        }) : _.setData({
          room_id: '请等待老师分配房间后查看'
        });
        peer_status ? _.setData({
          peer_status: '已确认'
        }) : _.setData({
          peer_status: '未确认'
        });
        sex == 1 ? _.setData({
          sex: '男'
        }) : _.setData({
          sex: '女'
        });
        room_pn == 4 ? _.setData({
          room_pn: '四人间'
        }) : _.setData({
          room_pn: '六人间'
        });
        room_type == 1 ? _.setData({
          room_type: '上下床'
        }) : _.setData({
          room_type: '上床下桌'
        })
        _.setData({
          list: res.data.list[0]
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})